define(["app","js/services/MuseService",'js/services/MessageBox'],
    function (app) {
        var deps = ["$scope", "$http", "$rootScope", "$filter", "$state", "$stateParams","MuseService","MessageBox"];

        function controller($scope, $http, $rootScope, $filter, $state, $stateParams,MuseService,MessageBox) {
            $scope.curUser = getSessionJson('curUserObj');

            if(isEmpty($scope.curUser)){
                var url = 'admin.html';
                location.replace(url);
            }

            $scope.ownerList =[];
            $scope.driver = {};
            $scope.type = "";


            $scope.name = "";

            $scope.btnClick = function(type){
                $scope.type = type;
            }

            $scope.getdriverList = function () {
                MuseService.post('driver/getMyDriverList',{userId:$scope.curUser.id,name:$scope.name}).success(
                    function(data){
                        if (data.code == 0) {
                            $scope.ownerList = data.data;
                        } else {
                            MessageBox.error('错误：' + data.msg);
                        }
                    }
                )

            };

            $scope.getdriverList();

            //新增修改操作同一个
            // 打开用户详细
            $scope.openDetailModal =  function(id) {
                $state.go("ownerdriverdetail", {
                    "id" : id
                });
            }

            //绑定车辆页面
            $scope.openCarDetail = function(id){
                //跳转前先判断是否有车辆再审核中

                MuseService.post("car/car/"+id, {
                    id : id
                }).success(function(data) {
                    if (data.code == 0) {
                        if(data.data && data.data.isEffect && data.data.isEffect == 'check'){
                            MessageBox.error("你的车辆审核中!请稍后");
                            return;
                        }

                        $state.go("cardetail", {
                            "id" : id
                        });

                    } else {
                        MessageBox.error("查询失败:" + data.msg);
                    }
                });
            }

            $scope.checkDriver = function (vo,type) {

                MuseService.post('check/checkDriver',{id:vo.id,type:type}).success(
                    function(data){
                        if (data.code == 0) {
                            MessageBox.notify("提交成功！");

                            vo.isEffect = type;
                        } else {
                            MessageBox.error('错误：' + data.msg);
                        }
                    }
                )

            };
            // 取消，返回
            $scope.close = function () {
                history.back();
            };
        }

        controller.$inject = deps;
        app.lazy.controller("OwnerDriverController", controller);
    });